<?php
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../_config/setting/global.setting.php';
	require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../plugin/Smarty/libs/Smarty.class.php';
?>
<?php
	$smarty = new Smarty();
	$smarty->setTemplateDir(__DIR__.DIRECTORY_SEPARATOR . '../view'.DIRECTORY_SEPARATOR.'templates');
    $smarty->setCompileDir(__DIR__.DIRECTORY_SEPARATOR . '../view'.DIRECTORY_SEPARATOR.'templates_c');
    $templateDir = $smarty->getTemplateDir(0);
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/BartuserService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/CustomerService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/FactoryService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/CountryService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/WoodService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Entity/Domain/WoodDomain.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/ArticleService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/ColourService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/LineService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Service/EmailService.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Context/BaseContext.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/ServiceResult/ServiceResult.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../_config/setting/PageConfig.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../_config/setting/SMTPConfig.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Util/Pager.php';
    require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../model/Util/Tool.php';
    
?>
<?php 	
		$templateDir = $smarty->getTemplateDir(0) ;
		$smarty->assign('templateDir',$glb["websiteURL"]."/view/templates");
		$smarty->assign('websiteURL',$glb["websiteURL"]);
		$smarty->assign('get',$_GET);
		$smarty->display($templateDir . "/temp1/head.tpl");
?>
<?php 
        	$context = new BaseContext();
			$result = new ServiceResult();
			$p = new Pager();
			
			$countryService = new CountryServices();
			$countryList = $countryService->findAllCountry($context, $result);
			
			$colourService = new ColourServices();
			$colourList = $colourService->findAllColour($context, $result);
			
			$lineService = new LineServices();
			$lineList = $lineService->findAllLine($context, $result);
			
			$woodService = new WoodServices();
			$woodList = $woodService->findAllWood($context, $result);
			
        	if(isset($_GET['func']))
        	{
        		$func = $_GET['func'];
        		$bartUserServices = new BartuserService();
        		if($func == "user")
        		{
        			if(isset($_GET['opt']))
        			{ 
        				$opt = $_GET['opt'];
        				if($opt == "add")
        				{
							$smarty->display($templateDir . "/temp1/addBArtUser.tpl");
        				}
	        			if($opt == "edit")
	        			{ 
	        				
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$bArtUser = $bartUserServices->getBArtUserByOid($context, $result, $_GET['id']);
	        					$smarty->assign('bArtUser', $bArtUser);
								$smarty->display($templateDir . "/temp1/editBArtUser.tpl");
	        				}
	        			}
						if($opt == "list")
						{ 			
							$start=$p->findStart($configPage['limit']);
							$count=$bartUserServices->countAllBArtUser($context, $result);
							$pages=$p->findPages($count,$configPage['limit']);
							$page_list = $p->pagesList($_GET['page'],$pages,$configPage);						
							$bartUserList = $bartUserServices->getAllBArtUserByRange($context, $result, $start, $configPage['limit']);
							$total = "Page ".$_GET['page']." in ".$pages. " Pages";
							$smarty->assign('total', $total);
							$smarty->assign('page_list', $page_list);
							$smarty->assign('bartUserList', $bartUserList);	
							$smarty->display($templateDir . "/temp1/listBArtUser.tpl"); 
						}
        			}
        		}
        		if($func == "cus")
        		{
        			$customerServices = new CustomerServices();
        			if(isset($_GET['opt']))
        			{ 
        				$opt = $_GET['opt'];
	        			if($opt == "add")
	        			{ 
	        				$smarty->assign('countryList', $countryList);
							$smarty->display($templateDir . "/temp1/addCustomer.tpl");
	        			}
        				if($opt == "edit")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$customerUser = $customerServices->getCustomerByOid($context, $result, $_GET['id']);
	        					$smarty->assign('customerUser', $customerUser);
	        					$smarty->assign('countryList', $countryList);
								$smarty->display($templateDir . "/temp1/editCustomer.tpl");
	        				}
	        			}
						if($opt == "list")
						{ 
							$start=$p->findStart($configPage['limit']);
							$count=$customerServices->countAllCustomer($context, $result);
							$pages=$p->findPages($count,$configPage['limit']);
							$page_list = $p->pagesList($_GET['page'],$pages,$configPage);	
							$customerList = $customerServices->getAllCustomerByRange($context, $result, $start, $configPage['limit']);
							$total = "Page ".$_GET['page']." in ".$pages. " Pages";
							$smarty->assign('total', $total);
							$smarty->assign('page_list', $page_list);
							$smarty->assign('customerList', $customerList);	
							$smarty->display($templateDir . "/temp1/listCustomer.tpl"); 
						}
        			}
        		}
        			
        		if($func == "fact")
        		{
        			$factoryServices = new FactoryServices();
        			if(isset($_GET['opt']))
        			{ 
        				$opt = $_GET['opt'];
	        			if($opt == "add")
		        		{ 
		        			$smarty->assign('countryList', $countryList);
							$smarty->display($templateDir . "/temp1/addFactory.tpl");
		        		}
        				if($opt == "edit")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$factoryUser = $factoryServices->getFactoryByOid($context, $result, $_GET['id']);
	        					$smarty->assign('factoryUser', $factoryUser);
	        					$smarty->assign('countryList', $countryList);
								$smarty->display($templateDir . "/temp1/editFactory.tpl");
	        				}
	        			}
						if($opt == "list")
						{
							$start=$p->findStart($configPage['limit']);
							$count=$factoryServices->countFactory($context, $result);
							$pages=$p->findPages($count,$configPage['limit']);
							$page_list = $p->pagesList($_GET['page'],$pages,$configPage);	
							$factoryList = $factoryServices->getAllFactoryByRange($context, $result, $start, $configPage['limit']);
							$total = "Page ".$_GET['page']." in ".$pages. " Pages";
							$smarty->assign('total', $total);
							$smarty->assign('page_list', $page_list);
							$smarty->assign('factoryList', $factoryList);	
							$smarty->display($templateDir . "/temp1/listFactory.tpl"); 
						}
        			}
        		}	
        		
        		if($func == "article")
        		{
        			$articleService = new ArticleService();
        			if(isset($_GET['opt']))
        			{ 
        				$opt = $_GET['opt'];
	        			if($opt == "add")
		        		{ 
							$smarty->display($templateDir . "/temp1/addArticle.tpl");
		        		}
        				if($opt == "edit")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$data = array();
	        					$article = $articleService->getArticleByOid($context, $result, $_GET['id']);
	        					$data['imagePath0'] = $article->getArticleDomain()->getImagePath0();
	        					$data['imagePath1'] = $article->getArticleDomain()->getImagePath1();
	        					$data['imagePath2'] = $article->getArticleDomain()->getImagePath2();
	        					$data['imagePath3'] = $article->getArticleDomain()->getImagePath3();
	        					$smarty->assign('colourList', $colourList);
	        					$smarty->assign('lineList', $lineList);
	        					$smarty->assign("woodList",$woodList);
	        					$smarty->assign('article', $article);
	        					$smarty->assign('data', $data);
								$smarty->display($templateDir . "/temp1/editArticle.tpl");
	        				}
	        			}
						if($opt == "list")
						{
							$start=$p->findStart($configPage['limit']);
							$count=$articleService->countAllArticle($context, $result);
							$pages=$p->findPages($count,$configPage['limit']);
							$page_list = $p->pagesList($_GET['page'],$pages,$configPage);	
							$articleList = $articleService->getAllArticleByRange($context, $result, $start, $configPage['limit']);
							$total = "Page ".$_GET['page']." in ".$pages. " Pages";
							$smarty->assign('total', $total);
							$smarty->assign('page_list', $page_list);
							$smarty->assign('articleList', $articleList);	
							$smarty->display($templateDir . "/temp1/listArticle.tpl"); 
						}
						
        				if($opt == "editColor")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$color = $colourService->findAllByOid($context, $result, $_GET['id']);
	        					$smarty->assign('color', $color);
								$smarty->display($templateDir . "/temp1/editColor.tpl");
	        				}
	        			}
	        			
        				if($opt == "editLine")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$line = $lineService->findAllByOid($context, $result, $_GET['id']);
	        					$smarty->assign('line', $line);
								$smarty->display($templateDir . "/temp1/editLine.tpl");
	        				}
	        			}
	        			
        				if($opt == "editWood")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$wood = $woodService->findWoodByOid($context, $result, $_GET['id']);
	        					$smarty->assign('wood', $wood);
								$smarty->display($templateDir . "/temp1/editWood.tpl");
	        				}
	        			}
        			}
        		}
        		
        		if($func == "order")
        		{
        			if(isset($_GET['opt']))
        			{ 
        				$opt = $_GET['opt'];
	        			if($opt == "check")
	        			{ 
	        				$orderID = $_GET['id'];
	        				$smarty->assign("orderID", $orderID);
							$smarty->display($templateDir . "/temp1/check.tpl");
	        			}
	        			
        				if($opt == "edit")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					
	        				}
	        			}
						if($opt == "list")
						{ 
							
						}
        			}
        		}

        		if($func == "web")
        		{
        			if(isset($_GET['opt']))
        			{ 
        				$opt = $_GET['opt'];
	        			if($opt == "add")
	        			{ 
							//$smarty->display($templateDir . "/temp1/addOrder.tpl");
	        			}
	        			
        				if($opt == "editEmail")
	        			{ 
	        				if(isset($_GET['id']) && is_numeric($_GET['id']))
	        				{
	        					$host = Tool::decode($smtp['host'], "sTunnInVietnAm@2012#");
							    $port = Tool::decode($smtp['port'], "sTunnInVietnAm@2012#");
							    $user = Tool::decode($smtp['user'], "sTunnInVietnAm@2012#");
							    $pass = Tool::decode($smtp['pass'], "sTunnInVietnAm@2012#"); 
								$emailService = new EmailService($host, $port, $user, $pass);
	        					$email = $emailService->findEmailByOid($context, $result, $_GET['id']);
	        					$smarty->assign('email', $email);
								$smarty->display($templateDir . "/temp1/editEmail.tpl");
	        				}
	        			}
						if($opt == "list")
						{ 
							
						}
        			}
        		}
        	}
        ?>